﻿Public Class masdrguse
    Private USEID = Nothing
    Private UGID = Nothing
    Private DUSENAME = Nothing
    Private DUSENAME_EN = Nothing
    Private STATUS = Nothing
    Private selectMasdrguse = "SELECT `useid` AS 'รหัส',`ugid` AS 'ประเภทการใช้ยา',`dusename` AS 'วิธีการใช้ยา', `dusename_en` AS 'วิธีการใช้ยา (Eng)',`status` AS 'สถานะการเปิดใช้งาน' FROM masdrguse"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property USEID_ As Integer
        Get
            Return USEID
        End Get
        Set(value As Integer)
            USEID = value
        End Set
    End Property

    Property UGID_ As String
        Get
            Return UGID
        End Get
        Set(value As String)
            UGID = value
        End Set
    End Property

    Property DUSENAME_ As String
        Get
            Return DUSENAME
        End Get
        Set(value As String)
            DUSENAME = value
        End Set
    End Property

    Property DUSENAME_EN_ As String
        Get
            Return DUSENAME_EN
        End Get
        Set(value As String)
            DUSENAME_EN = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrguse_ As String
        Get
            Return selectMasdrguse
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasdrguseData()
        If TypeOf DUSENAME Is String Then
            If connect.GetTable("SELECT useid FROM masdrguse WHERE dusename = '" & DUSENAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลวิธีการใช้ยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masdrguse (ugid, dusename, dusename_en, status) VALUES ('" & UGID & "', '" & DUSENAME & "', '" & DUSENAME_EN & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลวิธีการใช้ยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasdrguseData()
        If TypeOf DUSENAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masdrguse SET ugid = '" & ugid & "', dusename = '" & DUSENAME & "', dusename_en = '" & DUSENAME_EN & "', status = '" & STATUS & "' WHERE useid = '" & USEID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลวิธีการใช้ยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
